<%@ page language="java" import="java.util.*, com.rmt.www.vo.*" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
 
	<link href="css/Site.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" language="javascript" src="js/jquery-1.7.1.js"></script>
	<script src="js/jquery-ui-1.8.18.custom.min.js"></script>
		<link href="css/jquery-ui-1.8.18.custom.css" rel="stylesheet"
			type="text/css" />
	<script>
		$(function(){
			$( "input:submit, :button").button();
			//默认隐藏添加用户和编辑用户的表单
			$('#addUserForm').hide();
			$('#editUserForm').hide();
			
			//注册用户点击edit按钮的事件
			$('input[value="edit"]').click(function(){
				
				var i = $('input:checked').length;
				if (i != 1) { //选择且只能选择一个用户
					alert("please choose only one user to edit!");
					//恢复所有用户都不勾选状态
				    $("input:checked").each(function(){	
				    	$(this).attr("checked", "false");
				    });
				} else {
					//显示编辑用户表单界面
				    $('#editUserForm').toggle();
					$('#addUserForm').hide();
				    var uid = $("input:checked").attr("value");
				    var row = $("input:checked").parent().parent();
				    //获得用户类型
				    var type = row.children().eq(1).html().trim(); 
				    var typeSelect = "#editUserType option[value=" + type + "]";
				    //设置编辑表单中默认填充数据为用户当前信息
				    $(typeSelect).attr("selected", "selected");
				    var name = row.children().eq(2).html().trim();
				    $("#editUserName").val(name);
				    var password = row.children().eq(3).html().trim();
				    $("#editUserPassword").val(password);
				    $("#editUserId").val(uid);
				    $("input:checked").each(function(){
                        $(this).attr("checked", "false");
                    });
				}
			});
			
			//注册用户点击add按钮的事件
			$('input[value="add"]').click(function(){
				 $('#addUserForm').toggle();
				 $('#editUserForm').hide();
			});
			
			//注册用户点击delete按钮的事件
			$('input[value="delete"]').click(function(){
				var i=$('input:checked').length;
			 	var url='deleteUser?';
				if(i<1){ //至少选择一个用户
					alert('please choose at least one user!');
				}else{
					//获得已经选择的用户的uid主键
					$('input:checked').each(function(){
					 	url=url+'uids='+$(this).attr('value')+'&';
					});
					url=url.slice(0,-1);
					//ajax调用后台删除用户
					$.ajax({
					  url: url,
					  cache:false,
					  success: function(returnData, textStatus) {
					  	  $('input:checked').each(function(){
					 			$(this).parent().parent().hide();
					 			$(this).attr('checked',false);
							});
						},
					    error: function(xhr, textStatus, errorThrown) {
					      	alert('failed');
					    }
					});
				}
				
			});
		});
	</script>
	  <style type="text/css"> 
/* CSS Document */ 

a { 
color: #c75f3e; 
} 

#mytable { 
padding: 0; 
margin: 0; 
} 

caption { 
padding: 0 0 5px 0; 
width: 700px; 
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
text-align: right; 
} 

#mytable th { 
font: bold 14px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
color: #4f6b72; 
border-right: 1px solid #C1DAD7; 
border-bottom: 1px solid #C1DAD7; 
border-top: 1px solid #C1DAD7; 
letter-spacing: 2px; 
text-transform: uppercase; 
text-align: left; 
padding: 6px 6px 6px 12px; 
background: #CAE8EA  no-repeat; 
} 
 
#mytable th.nobg { 
border-top: 0; 
border-left: 0; 
border-right: 1px solid #C1DAD7; 
background: none; 
} 

#mytable td { 
border-right: 1px solid #C1DAD7; 
border-bottom: 1px solid #C1DAD7; 
background: #fff; 
font-size:13px; 
padding: 6px 6px 6px 12px; 
color: #4f6b72; 
} 
/*power by www.winshell.cn*/ 

#mytable td.alt { 
background: #F5FAFA; 
color: #797268; 
} 

#mytable th.spec { 
border-left: 1px solid #C1DAD7; 
border-top: 0; 
background: #fff no-repeat; 
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
} 

#mytable th.specalt { 
border-left: 1px solid #C1DAD7; 
border-top: 0; 
background: #f5fafa no-repeat; 
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
color: #797268; 
} 
</style> 
  </head>

  <body>
  <div class='page'>
  <div id="header" style='background-color: #5c87b2'>
            <div id="title">
                <h1>&nbsp;&nbsp;RMT Service for administrator</h1>
            </div>
              
            <div id="logindisplay">
                welcome <%=((User)session.getAttribute("currentUser")).getName()%>,  <a href='../RMT'>logout</a>
            </div> 
            <br/>
            <div id="menucontainer">
            
                <ul id="menu"> 
                	<li><a href="adminHomeAction">Home</a></li>             
                    <li><a href='getProjectsForAdmin'>Projects</a></li>
                    <li><a href='accountManageAction?manageTarget=account'>Users</a></li>
                </ul>
            
            </div>
        </div>
  
	<div id="main">
	<h1>Manage Users</h1>
		<center>
	   <table id="mytable">
        <tr>
            <th>
                choose
            </th>
            <th>
                user type
            </th>
            <th>
                user name   
            </th>
            <th>
                password
            </th>
        </tr>
        <s:iterator value="userList" id="list" status="st">
        <tr>
            <td>
                <input  type="checkbox" value='<s:property value="#list.uid" />' />
            </td>
            <td>
                <s:property value="#list.type" /> 
            </td>
            <td>
                <s:property value="#list.name" /> 
            </td>
            <td>
                <s:property value="#list.password" /> 
            </td>
        </tr>
        </s:iterator>
    </table>
    
    <br/>
    <tr>
        <td><input type="button" value='add' /></td>
        <td><input type="button" value="delete"/></td>
        <td><input type="button" value='edit' /></td>
    </tr>
   	<br />
    <form id='addUserForm' action='addUser' method='post'>
    <table style="border: hidden">
        <tr style="border: hidden">
           <td  style="border: hidden">
               type    
           </td>
           <td style="border: hidden">
               <select name="type" style="width:200px">
                  <option value ="admin">ADMIN</option>
                  <option value ="req">RSE</option>
                  <option value="dev">DEV</option>
                  <option value="test">TEST</option>
                </select>
           </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden">
                user name
            </td>
            <td style="border: hidden">
                <input type='text' name='username' />
            </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden">
                password
            </td>
            <td>
                <input type="text" name="password"/>
            </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden"></td>
            <td style="border: hidden">
                <input type='submit' value='submit' />
            </td>
        </tr>
    </table>
    </form>
    <form id='editUserForm' action='editUser' method='post'>
    <table  style="border: hidden">
        <tr style="display:none;">
            <td><input type='text' name='userid' id="editUserId"/></td>
        </tr>
        <tr  style="border: hidden">
           <td style="border: hidden">
               type    
           </td>
           <td style="border: hidden">
               <select name="type" id="editUserType" style="width:200px">
                  <option value ="admin">ADMIN</option>
                  <option value ="req">RSE</option>
                  <option value="dev">DEV</option>
                  <option value="test">TEST</option>
                </select>
           </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden">
                user name
            </td>
            <td>
                <input type='text' name='username' id="editUserName"/>
            </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden">
                password
            </td>
            <td>
                <input type="text" name="password" id="editUserPassword"/>
            </td>
        </tr>
        <tr style="border: hidden">
            <td style="border: hidden"></td>
            <td>
                <input type='submit' value='submit' />
            </td>
        </tr>
    </table>
    </form>
    </center>
	</div>
	 <div class="push"></div>
  	<div id="footer" style="background-color:#5c87b2;">
  	  <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:hidden;background-color:#5c87b2;">							
		<tbody style="border:hidden">
			<tr style="border: hidden">	
				<td width="160" style="border: hidden">&nbsp;</td>											   		<td>									
				<table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:hidden;">	
					<tbody style="border: hidden">
						<tr style="border: hidden">
							<td height="20px"><font color='#ffffff'>©2012 Copyright NJU SEI RMT team</font></td>										
						</tr>										
						<tr style="border: hidden">											
							<td height="20px"><font color='#ffffff'>2012 graduation project: requirement management tool</font></td>	
						</tr>										
						<tr style="border: hidden">					
							<td height="20px"><font color='#ffffff'>project homepage：http://code.google.com/p/rmt-ss/</font></td>		
						</tr>									
					</tbody>
				</table>								
				</td>							
			</tr>						
		</tbody>
	</table>	
  	</div>
    </div>
  </body>
</html>
